#include <iostream>
#include <vector>
#include "listnode.h"
using namespace std;

class Solution {
public:
    ListNode* ReverseList(ListNode* pHead) {
        if (pHead == nullptr) {
            return nullptr;
        }
        ListNode *p0 = nullptr;
        ListNode *p1 = pHead;
        ListNode *p2;
        while (p1 != nullptr) {
            p2 = p1->next;
            p1->next = p0;
            p0 = p1;
            p1 = p2;
        }
        return p0;
    }
};

int main() {
    cout << Solution().ReverseList(buildList({1, 2, 3, 4, 5, 6})) << endl;
    return 0;
}